import request from '@/utils/request'
enum API {
  LOGIN = '/user/user/login',
  LOGINROLE = '/user/user/loginRole',
  ADMIN_LOGIN = '/admin/admin/login',
  ALL_USERS = '/admin/usermgr/listAllUsers',
  REGISTER = '/user/user/register',
  INFO = '/user/user/getUserInfo',
  UPDATE_INFO = '/user/user/info',
  UPDATE_PASSWORD = '/user/user/password',
  ALL_PRODUCTS = '/user/Shelf/getAllShelf',
  SEARCH_PRODUCT = '/user/Shelf/searchByName',
  BUY = '/user/order/buy',
  ORDER = '/user/order/getOrderByUserId',
  CHARGE = '/user/user/recharge',
}
export interface BuyParams {
  shelfId: string
  quantity: number
}
export const enableUser = (userId: string) => request.put(`/admin/usermgr/enable/${userId}`)
export const disableUser = (userId: string) => request.put(`/admin/usermgr/disable/${userId}`)

export const listAllUsers = () => request.get(`${API.ALL_USERS}`)

export const adminLogin = (admin_id: string, adminPassword: string) =>
  request.post(`${API.ADMIN_LOGIN}?admin_id=${admin_id}&adminPassword=${adminPassword}`)

export const shipOrder = (orderId: string) => request.put(`/brands/products/${orderId}/ship`)

export const getOrder = () => request.get(`${API.ORDER}`)

export const buy = (params: BuyParams) => request.post(`${API.BUY}`, params)

export const allProducts = () => request.get(`${API.ALL_PRODUCTS}`)
export const searchByName = (product_name: string) =>
  request.get(`${API.SEARCH_PRODUCT}?Name=${product_name}`)

export const reqLogin = (userName: string, userPassword: string, role: string) =>
  request.post(`${API.LOGINROLE}?userId=${userName}&userPassword=${userPassword}&role=${role}`)
export const reqRegister = (
  userName: string,
  defaultName: string,
  userPassword: string,
  selectRole: string,
) =>
  request.post(
    `${API.REGISTER}?userId=${userName}&userName=${defaultName}&userPassword=${userPassword}&userRoleType=${selectRole}`,
  )
export const getInfo = () => request.get(`${API.INFO}`)

export const updateUserInfo = (userNickname: string, personal_info: string) =>
  request.put(`${API.UPDATE_INFO}?userName=${userNickname}&personal_info=${personal_info}`)

export const updatePassword = (oldPassword: string, newPassword: string) =>
  request.put(`${API.UPDATE_PASSWORD}?oldPassword=${oldPassword}&newPassword=${newPassword}`)
export const recharge = (cash: number) => request.put(`${API.CHARGE}?cash=${cash}`)
